/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package grest.view;

import grest.controller.CntrlrVistaBusqueda;
import grest.model.Entidad;
import grest.model.TableModelSL;
import java.awt.BorderLayout;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

/**
 *
 * @author Agustin
 */
public class VistaBusqueda extends JFrame{
    JTable tblBusqueda = new JTable();
    TableModelSL model;
    JScrollPane scBusqueda = new JScrollPane(tblBusqueda);
    JButton btnOk = new JButton("OK");
    Observable ob;
    
    
    public VistaBusqueda(Entidad ent,Observer observer){
        this.setLayout(new BorderLayout(5,5));
        this.add(btnOk,BorderLayout.SOUTH);
        this.add(scBusqueda,BorderLayout.CENTER);
        model = new TableModelSL(ent);
        tblBusqueda.setModel(model);
        tblBusqueda.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        CntrlrVistaBusqueda controlerBusqueda = new CntrlrVistaBusqueda(this);
        btnOk.addActionListener(controlerBusqueda);
        this.setSize(500,600);
        this.setVisible(true);
        ob = (Observable)controlerBusqueda;
        ob.addObserver(observer);
    }
    
    public JComponent getControls(String name){
        if(name.equals("tblBusqueda")) return tblBusqueda;
        else if(name.equals("btnOk")) return btnOk;
        else return null;
    }
    
    public void close(){
        this.dispose();
    }
}